home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / side.c < prev    next >
C/C++ Source or Header  |  1993-06-25  |  9KB  |  308 lines

  1.  
  2.    /***********************************************
  3.    *
  4.    *   file d:\cips\side.c
  5.    *
  6.    *   Functions: This file contains
  7.    *      main
  8.    *
  9.    *   Purpose:
  10.    *      This file contains the main calling
  11.    *      routine for a program which
  12.    *      takes two images and pastes them
  13.    *      together side by side or top to bottom
  14.    *      into a new image file.
  15.    *
  16.    *      There are three files: two input files
  17.    *      (file and file2), and one output
  18.    *      file (file3).
  19.    *
  20.    *   External Calls:
  21.    *      gin.c - get_image_name
  22.    *      numcvrt.c - get_integer
  23.    *                  int_convert
  24.    *      tiff.c - read_tiff_header
  25.    *      wtiff.c - does_not_exist
  26.    *                create_allocate_tiff_file
  27.    *      cutp.c - cut_image_piece
  28.    *               paste_image_piece
  29.    *
  30.    *   Modifications:
  31.    *      19 April 1992 - created
  32.    *
  33.    *************************************************/
  34.  
  35. #include "cips.h"
  36.  
  37.  
  38.  
  39. short the_image[ROWS][COLS];
  40. short out_image[ROWS][COLS];
  41.  
  42. main(argc, argv)
  43.    int argc;
  44.    char *argv[];
  45. {
  46.  
  47.    char     method[80], name[80], name2[80], name3[80];
  48.    int      a, b, count, il, ie, ll, le,
  49.             il2, ie2, ll2, le2,
  50.             il3, ie3, ll3, le3,
  51.             length, length2, length3,
  52.             width, width2, width3;
  53.    struct   tiff_header_struct image_header,
  54.                                image_header2,
  55.                                image_header3;
  56.  
  57.    my_clear_text_screen();
  58.  
  59.        /******************************************
  60.        *
  61.        *  Interpret the command line parameters.
  62.        *
  63.        *******************************************/
  64.  
  65.    if(argc < 5 || argc > 5){
  66.     printf(
  67.      "\n"
  68.      "\n usage: side in-file-1 in-file-2 "
  69.      "out-file method"
  70.      "\n        where method is Top-to-bottom "
  71.      "or Side-by-side"
  72.      "\n");
  73.     exit(0);
  74.    }
  75.  
  76.    strcpy(name,   argv[1]);
  77.    strcpy(name2,  argv[2]);
  78.    strcpy(name3,  argv[3]);
  79.    strcpy(method, argv[4]);
  80.  
  81.    if(does_not_exist(name)){
  82.       printf("\nERROR: Input file %s does not exist", 
  83.              name);
  84.       printf(
  85.        "\n"
  86.        "\n usage: side in-file-1 in-file-2 "
  87.        "out-file method"
  88.        "\n        where method is Top-to-bottom "
  89.        "or Side-by-side"
  90.        "\n");
  91.       exit(2);
  92.    }
  93.  
  94.    if(does_not_exist(name2)){
  95.       printf("\nERROR: Input file %s does not exist", 
  96.              name2);
  97.       printf(
  98.        "\n"
  99.        "\n usage: side in-file-1 in-file-2 "
  100.        "out-file method"
  101.        "\n        where method is Top-to-bottom "
  102.        "or Side-by-side"
  103.        "\n");
  104.       exit(3);
  105.    }
  106.  
  107.    if(method[0] != 't'   &&
  108.       method[0] != 'T'   &&
  109.       method[0] != 's'   &&
  110.       method[0] != 'S'){
  111.       printf("\nERROR: Did not choose a valid method");
  112.       printf(
  113.        "\n"
  114.        "\n usage: side in-file-1 in-file-2 "
  115.        "out-file method"
  116.        "\n        where method is Top-to-bottom "
  117.        "or Side-by-side"
  118.        "\n");
  119.       exit(4);
  120.    }
  121.  
  122.        /*******************************************
  123.        *
  124.        *   Look at the headers of the two input
  125.        *   files.  The output file will hold
  126.        *   most of the two inputs.
  127.        *
  128.        *   Allocate the output file to hold both
  129.        *   input files no matter which is larger
  130.        *   in either dimension.
  131.        *
  132.        ********************************************/
  133.  
  134.    read_tiff_header(name, &image_header);
  135.    round_off_image_size(&image_header,
  136.                         &length, &width);
  137.    read_tiff_header(name2, &image_header2);
  138.    round_off_image_size(&image_header2,
  139.                         &length2, &width2);
  140.  
  141.    if(method[0] == 'T' || method[0] == 't'){
  142.       length3 = length + length2;
  143.       width3  = width;
  144.       if(width2 > width3) width3 = width2;
  145.    }
  146.    else{
  147.       width3  = width + width2;
  148.       length3 = length;
  149.       if(length2 > length3) length3 = length2;
  150.    }
  151.  
  152.    image_header3.image_length   = length3*ROWS;
  153.    image_header3.image_width    = width3*COLS;
  154.    image_header3.lsb            = 1;
  155.    image_header3.bits_per_pixel = 8;
  156.    image_header3.strip_offset   = 1000;
  157.    create_allocate_tiff_file(name3, &image_header3,
  158.                              out_image);
  159.  
  160.        /********************************************
  161.        *
  162.        *   Loop through the two input images.  Cut
  163.        *   each image array from them and paste the
  164.        *   arrays into the output image.  Paste the
  165.        *   second input image to the left of the
  166.        *   first for the side by side option and
  167.        *   the second image below the first for the
  168.        *   top to bottom option.
  169.        *
  170.        *********************************************/
  171.  
  172.  
  173.        /*******************************************
  174.        *
  175.        *   First do the side by side option.
  176.        *
  177.        *********************************************/
  178.  
  179.    if(method[0] == 'S' || method[0] == 's'){
  180.       il    = 1;
  181.       ie    = 1;
  182.       ll    = 101;
  183.       le    = 101;
  184.       count = 1;
  185.  
  186.          /****************************************
  187.          *
  188.          *   Copy the first input file into the
  189.          *   left side of the output file.
  190.          *
  191.          *****************************************/
  192.  
  193.       for(a=0; a<length; a++){
  194.          for(b=0; b<width; b++){
  195.             printf("\ncut and paste %d of %d",
  196.                      count++, length*width);
  197.             cut_image_piece(name, the_image,
  198.                             il+a*ROWS, ie+b*COLS,
  199.                             ll+a*ROWS, le+b*COLS);
  200.             paste_image_piece(name3, name, the_image, 
  201.                               out_image,
  202.                               il+a*ROWS, ie+b*COLS,
  203.                               ll+a*ROWS, le+b*COLS);
  204.          }  /* ends loop over b */
  205.       }  /* ends loop over a */
  206.  
  207.       il2   = 1;
  208.       ie2   = 1;
  209.       ll2   = 101;
  210.       le2   = 101;
  211.       il3   = 1;
  212.       ie3   = 1+COLS*width;
  213.       ll3   = 101;
  214.       le3   = 101+COLS*width;
  215.       count = 1;
  216.  
  217.  
  218.          /****************************************
  219.          *
  220.          *   Copy the second input file into the
  221.          *   right side of the output file.
  222.          *
  223.          *****************************************/
  224.  
  225.       for(a=0; a<length2; a++){
  226.          for(b=0; b<width2; b++){
  227.             printf("\ncut and paste %d of %d",
  228.                      count++, length2*width2);
  229.             cut_image_piece(name2, the_image,
  230.                             il2+a*ROWS, ie2+b*COLS,
  231.                             ll2+a*ROWS, le2+b*COLS);
  232.             paste_image_piece(name3, name, the_image, 
  233.                               out_image,
  234.                               il3+a*ROWS, ie3+b*COLS,
  235.                               ll3+a*ROWS, le3+b*COLS);
  236.          }  /* ends loop over b */
  237.       }  /* ends loop over a */
  238.    }  /* ends if side-by-side method */
  239.  
  240.  
  241.        /********************************************
  242.        *
  243.        *   Now do the top to bottom option.
  244.        *
  245.        *********************************************/
  246.  
  247.    if(method[0] == 'T' || method[0] == 't'){
  248.       il    = 1;
  249.       ie    = 1;
  250.       ll    = 101;
  251.       le    = 101;
  252.       count = 1;
  253.  
  254.          /****************************************
  255.          *
  256.          *   Copy the first input file into the
  257.          *   top half of the output file.
  258.          *
  259.          *****************************************/
  260.  
  261.       for(a=0; a<length; a++){
  262.          for(b=0; b<width; b++){
  263.             printf("\ncut and paste %d of %d",
  264.                      count++, length*width);
  265.             cut_image_piece(name, the_image,
  266.                             il+a*ROWS, ie+b*COLS,
  267.                             ll+a*ROWS, le+b*COLS);
  268.             paste_image_piece(name3, name, the_image, 
  269.                               out_image,
  270.                               il+a*ROWS, ie+b*COLS,
  271.                               ll+a*ROWS, le+b*COLS);
  272.          }  /* ends loop over b */
  273.       }  /* ends loop over a */
  274.  
  275.       il2   = 1;
  276.       ie2   = 1;
  277.       ll2   = 101;
  278.       le2